#ifndef TCP_SESSION_CONFIG_H
#define TCP_SESSION_CONFIG_H
#include "io_session_config.h"

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>


namespace vpm
{
	namespace mina
	{		
		using boost::property_tree::ptree;

		static const char * TCP_SO_TCP_MODE = "TcpMode"; 
		static const char * TCP_SO_RECV_BUF_SIZE ="RecvBufSize"; 
		static const char * TCP_SO_SEND_BUF_SIZE = "SendBufSize"; 
		static const char * TCP_SO_TCP_SOLINGER  = "TcpSoLinger"; 
		static const char * TCP_SO_TCP_NODELAY   = "TcpNoDelay"; 
		static const char * TCP_SO_DO_NOT_ROUTE  = "DoNotRoute"; 
		static const char * TCP_SO_REUSE_ADDRESS = "ReuseAddress"; 

		class TcpSessionConfig  : public IoSessionConfig 
		{
		public:
			enum TcpMode 
			{
				TCP_ASYNCH, 
				TCP_SYNCH, 
			};

		
			TcpSessionConfig()
			{
				m_tcpSessionOptions.put(TCP_SO_RECV_BUF_SIZE,0);// 0 will use the  tcp default value
				m_tcpSessionOptions.put(TCP_SO_SEND_BUF_SIZE,0);
				m_tcpSessionOptions.put(TCP_SO_TCP_SOLINGER,false);	
				m_tcpSessionOptions.put(TCP_SO_TCP_NODELAY,false);
				m_tcpSessionOptions.put(TCP_SO_TCP_MODE,(int)TCP_ASYNCH);
				m_tcpSessionOptions.put(TCP_SO_DO_NOT_ROUTE,false);
				m_tcpSessionOptions.put(TCP_SO_DO_NOT_ROUTE,false);
                m_tcpSessionOptions.put(TCP_SO_REUSE_ADDRESS,false); 
			}

          
			inline int get_receive_buffer_size()
			{
				return m_tcpSessionOptions.get<int>(TCP_SO_RECV_BUF_SIZE);
			}

			inline void set_receive_buffer_size(int bufsize)
			{
				m_tcpSessionOptions.put(TCP_SO_RECV_BUF_SIZE,bufsize);
			}

			inline int get_send_buffer_size()
			{				
				return m_tcpSessionOptions.get<int>(TCP_SO_SEND_BUF_SIZE);
			}

			inline void set_send_buffer_size(int bufsize)
			{
				m_tcpSessionOptions.put(TCP_SO_SEND_BUF_SIZE,bufsize);
			}

			inline bool get_so_linger()
			{
				return m_tcpSessionOptions.get<bool>(TCP_SO_TCP_SOLINGER);
			}

			inline void set_so_linger(bool flag)
			{
				m_tcpSessionOptions.put(TCP_SO_TCP_SOLINGER,flag);				
			}

			inline bool get_tcp_nodelay()
			{
				return m_tcpSessionOptions.get<bool>(TCP_SO_TCP_NODELAY);
			}

			inline void set_tcp_nodelay(bool flag)
			{				
				m_tcpSessionOptions.put(TCP_SO_TCP_NODELAY,flag);
			}

			inline void set_tcp_mode(TcpMode mode)
			{				
				m_tcpSessionOptions.put(TCP_SO_TCP_MODE,(int)mode);
			}

			inline TcpMode get_tcp_mode()
			{
				return (TcpMode)m_tcpSessionOptions.get<int>(TCP_SO_TCP_MODE);				
			}

            inline bool get_tcp_do_not_route()
            {
                return m_tcpSessionOptions.get<bool>(TCP_SO_DO_NOT_ROUTE); 
            }

            inline void set_tcp_do_not_route(bool flag)
            {
                m_tcpSessionOptions.put(TCP_SO_DO_NOT_ROUTE,flag); 
            }
            inline bool get_tcp_reuse_sddress()
            {
                return m_tcpSessionOptions.get<bool>(TCP_SO_REUSE_ADDRESS); 
            }
            inline void set_tcp_reuse_address(bool flag)
            {
                m_tcpSessionOptions.put(TCP_SO_REUSE_ADDRESS,flag); 
            }
			
		private:		
			ptree m_tcpSessionOptions; 
		};

		typedef boost::shared_ptr<TcpSessionConfig> TcpSessionConfigPtr; 
	}
}

#endif // TCP_SESSION_CONFIG_H


